
#include <iostream>
#include <unordered_map>
#include <cmath>

std::string word_to_digit(std::string word) {
    std::unordered_map<std::string, std::string> words = {
        {"zero", "0"},
        {"one", "1"},
        {"two", "2"},
        {"three", "3"},
        {"four", "4"},
        {"five", "5"},
        {"six", "6"},
        {"seven", "7"},
        {"eight", "8"},
        {"nine", "9"}
    };
    return words[word];
}

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= std::sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input_words, number_str;
    std::cin >> input_words;
    std::string words[3] = {word_to_digit(input_words), word_to_digit(input_words), word_to_digit(input_words)};

    number_str = words[0] + words[1] + words[2];

    if (!std::isdigit(number_str[0]) || !std::isdigit(number_str[1]) || !std::isdigit(number_str[2]) || number_str.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        int number = std::stoi(number_str);
        int lower_prime = 0, upper_prime = 0, i = 1;

        while (true) {
            if (number - i >= 0 && is_prime(number - i)) {
                lower_prime = number - i;
                break;
            }
            if (is_prime(number + i)) {
                upper_prime = number + i;
                break;
            }
            i++;
        }

        if (lower_prime != 0) {
            std::cout << lower_prime << std::endl;
        } else if (upper_prime != 0) {
            std::cout << upper_prime << std::endl;
        }
    }

    return 0;
}
